<?php
    /**
	 ** pc站一对一跳转对应手机站页面
	 ** d 判断跳转方向，默认pc->wap,如果是wap->pc添加参数d=1 默认0
	 ** catid 栏目id
	 ** id 文章id
	 ** page 分页,如果pc分页数量和wap分页数量不一致会造成跳转错误，
	 ** 跳转对于单页面，手机版需要开发单页面控制器
	 ** 版权：郑州腾石建站 http://www.tengcee.com
	 ** 时间：2018-06-18
	 */
	defined('IN_PHPCMS') or exit('No permission resources.'); 
    pc_base::load_app_func('util','content');
	define('SITE_PROTOCOL', isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://');
	define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));
	$siteid = 1;
	$catid      = intval($_GET['catid']); //用来接收请求的栏目id 
	$typeid     = intval($_GET['typeid']); //用来接收请求的栏目id 
    $id         = intval(trim($_GET['id'])) ? intval(trim($_GET['id'])) : ''; //文章id
	$page       = intval(trim($_GET['page'])) ? intval(trim($_GET['page'])) : 1; //默认第一页
	$d          = intval(trim($_GET['d'])) ?  intval(trim($_GET['d'])) : 0 ; //默认跳转方向
	
	$sitelist  = getcache('sitelist','commons');
	$CATEGORYS = getcache('category_content_' . $siteid, 'commons');
	$wap_site  = getcache('wap_site','wap');
	$types     = getcache('wap_type','wap');
	$wap       = $wap_site[$siteid];
	$pcurl     = $sitelist[$siteid]['domain'].'index.php';
	if($wap['domain']){
		$wapurl   = $wap['domain'].'index.php?';
	}else{
		$wapurl    = $sitelist[$siteid]['domain'].'index.php?m=wap';
	}

   if($d == 0){
		if($catid){
			foreach($types as $type){
				if($type['cat'] == $catid && $type['siteid'] == $siteid){
					$typeid = $type['typeid'];
				}
			}
			
			if($id){//文章跳转
				  $wapurl =  $wapurl."&a=show&typeid=$typeid&catid=$catid&id=$id";
			}else{//栏目跳转
				 $wapurl =  $wapurl."&a=lists&typeid=$typeid&page=$page";
			}	
		}
		$meta = '<meta name="wapurl" content="'.$wapurl.'">';
		
	}else{
	    if($typeid || $catid){
		   if(!empty($typeid)){
		       foreach($types as $type){
				  if($type['typeid'] == $typeid && $type['siteid'] == $siteid){
					$catid = $type['cat'];
				  }
			  }
		   }else{
		       $catid = $catid;
		   }
		   $modelid = $CATEGORYS[$catid]['modelid'];
		   $type    = $CATEGORYS[$catid]['type'];
		   if($type == 2){//跳转链接
		       $pcurl = $CATEGORYS[$catid]['url'];
			   $flag  = 0;
		   }else{
		       if(empty($id) && empty($catid)){
			      //无动作 
			   }else{
			        if($id){//文章跳转
						$db = pc_base::load_model('content_model');//引入content模型 
						$db->set_model($modelid); //设置模型id，如果是其他非文章模型可以不需要设置这个
						$data = $db->get_one(array('id' => $id),'*'); 
						$pcurl2 = str_replace(array('www.','http://','https://'),array('','',''),$sitelist[$siteid]['domain']);//获取主域名
						$flag   = trim($data['islink']) ? 0 : 1;
						if(strpos($data['url'],$pcurl2) || ($data['islink'] == 1)){
						   $pcurl = $data['url'];
						}else{
						   $pcurl = $pcurl.$data['url'];
						}
					}else{//栏目跳转
						$pcurl =  $CATEGORYS[$catid]['url'];
					}
			   }
		   }
		  
			
		}
		if($flag){
		   $meta = '<meta name="wapurl" content="'.$pcurl.'" islink ="0">';
		}else{
		    $meta = '<meta name="wapurl" content="'.$pcurl.'" islink ="1">';
		}
		
	}
	
?>
$('head meta:first').before('<?php echo $meta?>');